package com.haoshuang.zhouzhoubang.ui.vm

import androidx.lifecycle.rxLifeScope
import com.haoshuang.zhouzhoubang.base.request
import com.lnkj.jialubao.utils.AccountUtils
import com.mufeng.libs.base.BaseViewModel
import com.mufeng.libs.state.StateData
import com.mufeng.libs.state.StatefulMutableLiveData

class ChangePhoneNumberViewModel : BaseViewModel() {

    val getData2 = StatefulMutableLiveData<Any>()
    fun getData2(vararg params: Pair<String, Any?>) {
        rxLifeScope.launch {
            request<Any>("/api/user/upt_mobile", *params,
                onStart = {
                    getData2.value = StateData.Loading
                },
                onError = { code, msg ->
                    getData2.value = StateData.Error(code, msg)
                }, onSuccess = {
                    getData2.postValue(StateData.Success(it))
                })
        }
    }
    val sendSmsData = StatefulMutableLiveData<Any>()
    fun sendSms(vararg params: Pair<String, Any?>) {
        rxLifeScope.launch {
            request<Any>("/api/Sms/send", *params,
                onStart = {
                    sendSmsData.value = StateData.Loading
                },
                onError = { code, msg ->
                    sendSmsData.value = StateData.Error(code, msg)
                }, onSuccess = {
                    sendSmsData.value = StateData.Success(it)
                })

        }
    }
    val sendSmsData2 = StatefulMutableLiveData<Any>()
    fun sendSms2(vararg params: Pair<String, Any?>) {
        rxLifeScope.launch {
            request<Any>("/api/Sms/send", *params,
                onStart = {
                    sendSmsData2.value = StateData.Loading
                },
                onError = { code, msg ->
                    sendSmsData2.value = StateData.Error(code, msg)
                }, onSuccess = {
                    sendSmsData2.value = StateData.Success(it)
                })

        }
    }
}